
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Features &#8212; pyungo v0.7.0 documentation</title>
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Developer Documentation" href="developer.html" />
    <link rel="prev" title="Getting Started" href="gettingstarted.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  <div class="document">
    
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<p class="logo">
  <a href="../index.html">
    <img class="logo" src="../_static/pyungo.jpg" alt="Logo"/>
    
  </a>
</p>






<p>
<iframe src="https://ghbtns.com/github-btn.html?user=cedricleroy&repo=pyungo&type=star&count=true&size=large&v=2"
  allowtransparency="true" frameborder="0" scrolling="0" width="200px" height="35px"></iframe>
</p>





<h3>Navigation</h3>
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="gettingstarted.html">Getting Started</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Features</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#sanity-check">Sanity Check</a></li>
<li class="toctree-l2"><a class="reference internal" href="#add-a-node-explicitely">Add a <code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code> explicitely</a></li>
<li class="toctree-l2"><a class="reference internal" href="#parallelism">Parallelism</a></li>
<li class="toctree-l2"><a class="reference internal" href="#args-kwargs-constants">Args, Kwargs, Constants</a></li>
<li class="toctree-l2"><a class="reference internal" href="#input-and-output-objects"><code class="xref py py-class docutils literal notranslate"><span class="pre">Input</span></code> and <code class="xref py py-class docutils literal notranslate"><span class="pre">Output</span></code> objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="#schema">Schema</a></li>
<li class="toctree-l2"><a class="reference internal" href="#name-mapping">Name mapping</a></li>
<li class="toctree-l2"><a class="reference internal" href="#contracts">Contracts</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="developer.html">Developer Documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatsnew.html">What’s New</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
      <li>Previous: <a href="gettingstarted.html" title="previous chapter">Getting Started</a></li>
      <li>Next: <a href="developer.html" title="next chapter">Developer Documentation</a></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <div class="section" id="features">
<h1>Features<a class="headerlink" href="#features" title="Permalink to this headline">¶</a></h1>
<div class="section" id="sanity-check">
<h2>Sanity Check<a class="headerlink" href="#sanity-check" title="Permalink to this headline">¶</a></h2>
<p><strong>pyungo</strong> will raise an error in the following situations:</p>
<ul class="simple">
<li><p>Circular dependencies: The <a class="reference internal" href="developer.html#pyungo.core.Graph" title="pyungo.core.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">Graph</span></code></a> need to be finite and cannot form a loop.</p></li>
<li><p>All inputs needed to run a <a class="reference internal" href="developer.html#pyungo.core.Graph" title="pyungo.core.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">Graph</span></code></a> are not provided.</p></li>
<li><p>Input collision: An input name provided as data in the <a class="reference internal" href="developer.html#pyungo.core.Graph" title="pyungo.core.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">Graph</span></code></a> has a
conflict with at least of the output name.</p></li>
<li><p>Duplicated outputs: Several nodes are giving output(s) that have the same name.</p></li>
</ul>
</div>
<div class="section" id="add-a-node-explicitely">
<h2>Add a <a class="reference internal" href="developer.html#pyungo.core.Node" title="pyungo.core.Node"><code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code></a> explicitely<a class="headerlink" href="#add-a-node-explicitely" title="Permalink to this headline">¶</a></h2>
<p>While the simple example register nodes at import time with a decorator, it is possible to
explicitely add a node a runtime. Here is the same example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">formulas</span> <span class="kn">import</span> <span class="n">f_my_function_1</span><span class="p">,</span> <span class="n">f_my_function_2</span><span class="p">,</span> <span class="n">f_my_function_3</span>

<span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span>

<span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="n">f_my_function_1</span><span class="p">,</span> <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">],</span> <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;e&#39;</span><span class="p">])</span>
<span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="n">f_my_function_2</span><span class="p">,</span> <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">],</span> <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">])</span>
<span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="n">f_my_function_3</span><span class="p">,</span> <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span> <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">])</span>

<span class="n">res</span> <span class="o">=</span> <span class="n">graph</span><span class="o">.</span><span class="n">calculate</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">})</span>
<span class="nb">print</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="parallelism">
<h2>Parallelism<a class="headerlink" href="#parallelism" title="Permalink to this headline">¶</a></h2>
<p>When resolving the dag, <strong>pyungo</strong> figure out nodes that can be run in parallel.
When creating a graph, we can specify the option <code class="docutils literal notranslate"><span class="pre">parallel=True</span></code> for running calculations
concurently when possible, using <a class="reference external" href="https://pypi.org/project/multiprocess/">multiprocess</a>
module. This package is not automatically installed with <strong>pyungo</strong>, and will need to be
installed manually if parallelism is used. We can specify the pool size when instantiating
the <a class="reference internal" href="developer.html#pyungo.core.Node" title="pyungo.core.Node"><code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code></a>. This will set the maximum number of processes that will be
launched. If 3 nodes can run in parallel and just 2 processes are used, <strong>pyungo</strong> will run
calculation on the first 2 nodes first and will run the last one as soon as a process
will be free.</p>
<p>Instantiating a <a class="reference internal" href="developer.html#pyungo.core.Graph" title="pyungo.core.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">Graph</span></code></a> with a pool of 5 processes for running
calculations in parralel:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">parallel</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">pool_size</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Running functions in parallel has a cost. Python will spend time creating / deleting
new processes. Parallelism is recommended when at least 2 concurrent nodes have heavy
calculations which takes a significant amount of time.</p>
</div>
</div>
<div class="section" id="args-kwargs-constants">
<h2>Args, Kwargs, Constants<a class="headerlink" href="#args-kwargs-constants" title="Permalink to this headline">¶</a></h2>
<p>If a function registred in a <a class="reference internal" href="developer.html#pyungo.core.Node" title="pyungo.core.Node"><code class="xref py py-class docutils literal notranslate"><span class="pre">Node</span></code></a> contains <code class="docutils literal notranslate"><span class="pre">args</span></code> or <code class="docutils literal notranslate"><span class="pre">kwargs</span></code>,
it is possible to define which data will be passed to them:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span>
    <span class="n">my_function</span><span class="p">,</span>
    <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span>
    <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">],</span>
    <span class="n">kwargs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;e&#39;</span><span class="p">,</span> <span class="s1">&#39;f&#39;</span><span class="p">],</span>
    <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;g&#39;</span><span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Sometimes, we want one of the input to be defined as a constant:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@graph</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">}],</span> <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">f_my_function</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
</pre></div>
</div>
<p>Then, only <code class="docutils literal notranslate"><span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">b</span></code> will be needed when calling <a class="reference internal" href="developer.html#pyungo.core.Graph.calculate" title="pyungo.core.Graph.calculate"><code class="xref py py-class docutils literal notranslate"><span class="pre">calculate</span></code></a>.</p>
</div>
<div class="section" id="input-and-output-objects">
<h2><a class="reference internal" href="developer.html#pyungo.io.Input" title="pyungo.io.Input"><code class="xref py py-class docutils literal notranslate"><span class="pre">Input</span></code></a> and <a class="reference internal" href="developer.html#pyungo.io.Output" title="pyungo.io.Output"><code class="xref py py-class docutils literal notranslate"><span class="pre">Output</span></code></a> objects<a class="headerlink" href="#input-and-output-objects" title="Permalink to this headline">¶</a></h2>
<p>Inputs and outputs can be defined directly with their names, or with <a class="reference internal" href="developer.html#pyungo.io.Input" title="pyungo.io.Input"><code class="xref py py-class docutils literal notranslate"><span class="pre">Input</span></code></a>
/ <a class="reference internal" href="developer.html#pyungo.io.Output" title="pyungo.io.Output"><code class="xref py py-class docutils literal notranslate"><span class="pre">Output</span></code></a> objects. This come in handy when there is extra behavior to be
attached to an input / output (e.g. <code class="docutils literal notranslate"><span class="pre">Contracts</span></code>).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pyungo.io</span> <span class="kn">import</span> <span class="n">Input</span><span class="p">,</span> <span class="n">Output</span>

<span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span>
    <span class="n">my_function</span><span class="p">,</span>
    <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="n">Input</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">),</span> <span class="n">Input</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;b&#39;</span><span class="p">)],</span>
    <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="n">Output</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;g&#39;</span><span class="p">)]</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Often, inputs are used multiple times across the nodes. In those cases, it is better to define
inputs only once (with their special features if any). It is possible to pass a list of
<a class="reference internal" href="developer.html#pyungo.io.Input" title="pyungo.io.Input"><code class="xref py py-class docutils literal notranslate"><span class="pre">Input</span></code></a> / <a class="reference internal" href="developer.html#pyungo.io.Output" title="pyungo.io.Output"><code class="xref py py-class docutils literal notranslate"><span class="pre">Output</span></code></a> objects a <a class="reference internal" href="developer.html#pyungo.core.Graph" title="pyungo.core.Graph"><code class="xref py py-class docutils literal notranslate"><span class="pre">Graph</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pyungo.io</span> <span class="kn">import</span> <span class="n">Input</span><span class="p">,</span> <span class="n">Output</span>

<span class="n">inputs</span> <span class="o">=</span> <span class="p">[</span><span class="n">Input</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">),</span> <span class="n">Input</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;b&#39;</span><span class="p">)]</span>
<span class="n">outputs</span> <span class="o">=</span> <span class="p">[</span><span class="n">Output</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;c&#39;</span><span class="p">),</span> <span class="n">Output</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;d&#39;</span><span class="p">)]</span>

<span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">outputs</span><span class="p">)</span>

<span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span>
    <span class="n">my_function</span><span class="p">,</span>
    <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span>
    <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">]</span>
<span class="p">)</span>

<span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span>
    <span class="n">my_other_function</span><span class="p">,</span>
    <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span>
    <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;d&#39;</span><span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If inputs / outputs are explicitely provided to a graph, inputs / outputs defined
in the nodes can only be strings.</p>
</div>
</div>
<div class="section" id="schema">
<h2>Schema<a class="headerlink" href="#schema" title="Permalink to this headline">¶</a></h2>
<p>Inputs validation is an important step to run a model with confidence. pyungo uses the
<a class="reference external" href="https://json-schema.org/">JSON Schema specification</a> through a Python library:
<a class="reference external" href="https://github.com/Julian/jsonschema">jsonschema</a>. The following is now possible:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">schema</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;object&quot;</span><span class="p">,</span>
    <span class="s2">&quot;properties&quot;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s2">&quot;a&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;number&quot;</span><span class="p">},</span>
        <span class="s2">&quot;b&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;number&quot;</span><span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">schema</span><span class="o">=</span><span class="n">schema</span><span class="p">)</span>

<span class="nd">@graph</span><span class="o">.</span><span class="n">register</span><span class="p">(</span>
    <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">],</span>
    <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;c&#39;</span><span class="p">]</span>
<span class="p">)</span>
<span class="k">def</span> <span class="nf">f_my_function</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>

<span class="n">graph</span><span class="o">.</span><span class="n">calculate</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="s1">&#39;2&#39;</span><span class="p">})</span>
</pre></div>
</div>
<p>The calculation is going to fail as <code class="docutils literal notranslate"><span class="pre">b</span></code> is of type string. It is better to catch this problem
early on before running the model. As we provided a schema saying we explicitely want <code class="docutils literal notranslate"><span class="pre">b</span></code> to
be of type <code class="docutils literal notranslate"><span class="pre">number</span></code>, the data validation against the schema will fail with the following error:
<code class="docutils literal notranslate"><span class="pre">'2'</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">of</span> <span class="pre">type</span> <span class="pre">'number'</span></code>.</p>
</div>
<div class="section" id="name-mapping">
<h2>Name mapping<a class="headerlink" href="#name-mapping" title="Permalink to this headline">¶</a></h2>
<p>Often, the name of the data we get are different from the ones used in the functions / models /
formulas. pyungo makes things easy providing a mapping feature. Here is an example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span>

<span class="nd">@graph</span><span class="o">.</span><span class="n">register</span><span class="p">(</span>
    <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="n">Input</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="nb">map</span><span class="o">=</span><span class="s1">&#39;q&#39;</span><span class="p">),</span> <span class="n">Input</span><span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="nb">map</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">)],</span>
    <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="n">Output</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="nb">map</span><span class="o">=</span><span class="s1">&#39;e&#39;</span><span class="p">)]</span>
<span class="p">)</span>
<span class="k">def</span> <span class="nf">f_my_function</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>

<span class="n">res</span> <span class="o">=</span> <span class="n">graph</span><span class="o">.</span><span class="n">calculate</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;q&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">})</span>
<span class="k">assert</span> <span class="n">res</span> <span class="o">==</span> <span class="mi">5</span>
<span class="k">assert</span> <span class="n">graph</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;e&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">5</span>
</pre></div>
</div>
</div>
<div class="section" id="contracts">
<h2>Contracts<a class="headerlink" href="#contracts" title="Permalink to this headline">¶</a></h2>
<p>Sometimes we want to make sure a value meet specific criteria before moving forward.
<strong>pyungo</strong> uses <a class="reference external" href="https://andreacensi.github.io/contracts/">pycontracts</a> for attaching
contracts to inputs or outputs.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pyungo.io</span> <span class="kn">import</span> <span class="n">Input</span><span class="p">,</span> <span class="n">Output</span>

<span class="n">graph</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span>
    <span class="n">my_function</span><span class="p">,</span>
    <span class="n">inputs</span><span class="o">=</span><span class="p">[</span><span class="n">Input</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="s1">&#39;&gt;0&#39;</span><span class="p">),</span> <span class="n">Input</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="s1">&#39;float&#39;</span><span class="p">)],</span>
    <span class="n">outputs</span><span class="o">=</span><span class="p">[</span><span class="n">Output</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;g&#39;</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="s1">&#39;float&#39;</span><span class="p">)]</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>


          </div>
          
        </div>
      </div>
    <div class="clearer"></div>
  </div>
    <div class="footer">
      &copy;2019, Cedric Leroy.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 3.1.0</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
      |
      <a href="../_sources/source/features.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    
    <a href="https://github.com/cedricleroy/pyungo" class="github">
        <img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"  class="github"/>
    </a>
    

    
  </body>
</html>